// pages/sells/sellsList/sellsList.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageNum: '1', //分页
    resultData: [], //数据源
    imgURL: app.globalData.imgURL, //图片总路径
    url: 'buyerpurinfo/resProductListByBid',
    orderSData: [],
    showViewId: 2,
    noOrdersMsg: '未查询到订单信息~~',
    openId: '',
    bId: '',
    customerType: '0',
  },
  showOrderDetail: function(e) {
    var that = this;
    // wx.navigateTo({
    //   url: '../resProductDetail/resProductDetail?id=' + e.currentTarget.id + "&openId=" + that.data.openId + "&type=" + that.data.customerType,
    // })
    wx.navigateTo({
      url: '../../buys/buysDetail/buysDetail?id=' + e.currentTarget.id + "&openId=" + that.data.openId + "&type=" + that.data.customerType +"&productShow=resProductList"
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var b_id = options.b_id;
    var that = this;
    that.setData({
      bId: b_id,
      openId: options.openId
    })
    that.requestData(b_id);
  },

  //请求数据
  requestData: function(b_id) {
    var that = this;
    app.post(that.data.url, {
      pageNum: that.data.pageNum,
      openId: that.data.openId,
      bId: b_id
    }).then((res) => {
      console.log('success');
      console.log(res);
      if (res.code == 0) {
        that.setData({
          orderSData: that.data.orderSData.concat(res.resultData),
        })

      } else {
        wx.showModal({
          title: '温馨提示',
          content: res.msg,
          showCancel: false,
        })
      }
      console.log("订单数量：" + this.data.orderSData.length);
      if (that.data.orderSData.length == 0) {
        that.setData({
          showViewId: 2,
        })
      } else {
        that.setData({
          showViewId: 1,
        })
      }
    }).catch((errMsg) => {
      console.log('fail');
      console.log(errMsg + '失败');
    })
  },
  res_goods_info: function(e) {

    wx.navigateTo({
      url: '../sellsReleaseInfo/sellsReleaseInfo?buyId=' + e.currentTarget.id,
    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    var that = this;
    that.setData({
      orderSData: [],
      pageNum: '1', //分页
      userInfo: wx.getStorageSync('userInfo'), //获取用户信息
    })
    wx.showNavigationBarLoading();
    setTimeout(function() {
      that.requestData();
      wx.stopPullDownRefresh();
      wx.hideNavigationBarLoading();
    }, 2000);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    console.log('加载更多');
    var that = this;
    that.data.pageNum++;
    console.log(that.data.pageNum);
    that.requestData();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})